package com.broadsoft.platform.wfengine.helper;

import java.io.InputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.broadsoft.platform.wfengine.ApplicationType;


/**
 * 
* FIXME: <A few lines of description of what class is about and what it does.> 
*
* <HR/><B>Modification Block</B>
* <P>
* Version: FIXME: 1.0.1 <BR>
* Author: FIXME: luzhen
* Date: 2011-9-15
* TAG: <A short name to find out all changed made by this modification.>
* Comments: Created.
* Bug fix NO.: <If required>
* </P>
* <P>
* ... Other Modifications following above structure.
* </P>
*
 */
public class UnmarshalHelper {
    
    private static final String PACKAGE_NAME_WFENGINE = "com.broadsoft.platform.wfengine";
     
    private final static Logger logger = LoggerFactory.getLogger(UnmarshalHelper.class);
    
    
    /**
     * 
     * FIXME: <A brief description of what the method does.> 
     * FIXME: Algorithm: <MUST exist if the method is more than 10 lines. Remove if it is simple.>
     * <An Algorithm in pure English, describing the logic used in the implementation. 
     * This should not contain to any Syntax of Java, in fact, it should be language independent, 
     * and should be targeted to any new comer in the maintenance of the code.>
     *
     * @param workflowFileResourceName
     * @return
     * @throws JAXBException
     */
    public static ApplicationType unmarshal(String workflowFileResourceName) throws JAXBException {
        JAXBContext jc = JAXBContext.newInstance(PACKAGE_NAME_WFENGINE); 
        Unmarshaller um = jc.createUnmarshaller();  
        InputStream isWorkflow = UnmarshalHelper.class.getResourceAsStream("/workflow/"+workflowFileResourceName);
        javax.xml.bind.JAXBElement<ApplicationType>  jAXBElement = (javax.xml.bind.JAXBElement) um.unmarshal(isWorkflow);
        ApplicationType applicationType=(ApplicationType)jAXBElement.getValue();
        if (logger.isTraceEnabled()) {
            logger.trace("The local variable[applicationType] is {}.", applicationType);
        }
        return applicationType;
    }//end of unmarshal
     
}//end of UnmarshalHelper
